<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Dangle
 *
 * @author sunday add 2014.5.28  modify by dragon.hu@2016.2.3
 */
require_once 'BaseChannel.php';

//拇指玩
class Muzhiwan implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="56ce9e22b78e9"; // 12位支付密钥
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; // 12位支付密钥
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("muzhiwan", $_REQUEST);
		$appkey=$_REQUEST["appkey"];
		$orderID=$_REQUEST["orderID"];
		$productName=$_REQUEST["productName"];
		$productDesc=$_REQUEST["productDesc"];
		$productID=$_REQUEST["productID"];
		$money=$_REQUEST["money"];
		$uid=$_REQUEST["uid"];
		$extern=$_REQUEST["extern"];
		$sign=$_REQUEST["sign"];
		/*
		 * appkey
			orderid
			productName
			productDesc
			productID
			money
			uid
			extern
		 */
		
		$mysign=$appkey.$orderID.$productName.$productDesc.$productID.$money.$uid.$extern;
		$mysign = $mysign.$paymentKey;
		
		//echo " sign=$sign ";
		//echo " mysign=$mysign ";
		
		if($sign == md5($mysign)) 
		//if(result != null ) //for test 
		{ //验证通过
			 
			//进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $money, $extern, "muzhiwan", $platform,$orderID))
			{
				$ret="FAILED";
				$orderLog->log("muzhiwan",array("order"=>$extern,"money"=>$money,"result"=>$result,"serverresult"=>"faild"));
				//echo " insert order:$ext error ";
			}else 
			{
				//支付成功
				$ret="SUCCESS";
				$orderLog->log("muzhiwan",array("order"=>$extern,"money"=>$money,"result"=>$result,"serverresult"=>"success"));
			}
			 
		} else {
			//"$sig验证失败"
			//echo "  order:$ext  sign error ";
			$orderLog->log("muzhiwan","  order:$extern  sign error sign:$sign mysign:$mysign");
			$ret="FAILED";
		}
		return $ret;
	}
	
}